<?php
class category_Model_Category 
{
	// mService->insert returns ('success', 'last-insert-id', 'errorMessage');
	public function __construct()
	{
	   	//require_once (APP_PATH. "/modules/category/Model/Category.php");
		//require_once (APP_PATH. "/modules/category/Model/Relations.php");
		$this->mCategory = new category_Model_Category();
		$this->mRelation = new category_Model_Relations();
		$this->db = Zend_Db_Table::getDefaultAdapter();
	}

	/*
	 * @return: array of ("success", "id" => id of the category with that $categoryName)
	 * 
	 */
	public function createNewUserCategory($userId, $nodeType, $categoryName)
	{
		$this->setUpTableNames("user");
		$ret = $this->mCategory->getCategoryByNameAndCreateIfNeeded($userId, 0);
    	if (!$ret['success'])
    	{
			return $ret;
    	}
    	$ret = $this->mCategory->getCategoryByNameAndCreateIfNeeded($nodeType, $ret['id']);
    	if (!$ret['success'])
    	{
			return $ret;
    	}
    	$ret = $this->mCategory->getCategoryByNameAndCreateIfNeeded($categoryName, $ret['id']);
    	return $ret;
	
	}
	
	public function setupTableNames($name)
	{
		$this->mCategory->setTables($name);
		$this->mRelation->setupTableName("category_relations_" . $name);
	}
}
?>